<?php
//a session is started
session_start();

$memberID = intval($_SESSION['member_id']);
?>
<html>
    <head>
        <title></title>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <?php
        echo "<h1> Latest News </h1>";

//establishing a database connection
        $conn = @mysql_connect('localhost', 'root', '') or die(mysql_error());
        mysql_select_db("mydb") or die(mysql_error());

        //executing the query that gets all the conferences' long names on which has been posted  
        $get_conferences = mysql_query("select DISTINCT long_name FROM o_postnews_conference p , conference c  WHERE  c.conference_id = p.conference_id AND p.ann_deadline > now() ") or die(mysql_error());
        //loop on the conferences to get each conference's news 
        while ($conferences = mysql_fetch_assoc($get_conferences)) {
            // store the conference's long name in a variable
            $conference_name = $conferences['long_name'];

            echo "<h2>{$conferences['long_name']}</h2>";
//executing the query that gets the news posted on a specific conference
            $get_news = mysql_query("Select ann_id, ann_title , ann_text , p.conference_id, p.member_id 
                FROM o_postnews_conference p , conference c 
                WHERE c.conference_id = p.conference_id 
                AND c.long_name = '$conference_name' 
                AND p.ann_deadline > now() ") or die(mysql_error());
            //loop on the news to display them in a table 
            while ($news = mysql_fetch_assoc($get_news)) {
                //Author: Aya El Mobayad
                //if the creatorid of the piece of news being printed is equivalent 
                //to the memberID of the logged in user
                if ($news['member_id'] == $memberID) {
                    //a link to delete the item is places beside it. 
                    //Its action takes place in the deleteNews page
                    echo '<table><tr><td>
                    <p style="font-size: 11pt;"><b>' . $news['ann_title'] . '</b></p>&nbsp&nbsp
                    <a href="deleteNews.php?ann_id=' . $news['ann_id'] . '">Delete</a></td></tr>
                <tr><td>' . $news['ann_text'] . '</td></tr></table>';
                    //if the user is not the one who posted the news
                } else {
                    echo " <table><tr><td>
                <h3>{$news['ann_title']}</h3></td></tr>
                <tr><td> {$news['ann_text']}</td></tr></table>";
                }
            }
        }
        //The connection is closed
        mysql_close($conn);

        //End Documentation
        ?>
    </body>
</html>


